package com.nuoniu.sibanyun.controller.erp;


import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.erp.ErpProject;
import com.nuoniu.sibanyun.entity.erp.ErpProjectPlan;
import com.nuoniu.sibanyun.entity.erp.ErpProjectType;
import com.nuoniu.sibanyun.service.erp.IErpProjectPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 项目计划 前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2021-10-24
 */
@RestController
@RequestMapping("/project/plan")
@Api(tags = "项目计划/里程碑管理")
public class ErpProjectPlanController extends BaseController {

    @Autowired
    private IErpProjectPlanService planService;

    @ApiOperation("获取列表")
    @GetMapping("getList")
    public HttpResult getList(ErpProjectPlan projectPlan) {
        return HttpResult.ok(planService.getList(projectPlan));
    }

    @ApiOperation("保存")
    @PostMapping("save")
    public HttpResult save(@RequestBody ErpProjectPlan projectPlan) {
        if(StringUtils.isBlank(projectPlan.getName())) {
            throw new NuoNiuException("名称不能为空");
        }

        if(projectPlan.getProjectId() == null) {
            throw new NuoNiuException("项目不能为空");
        }

        planService.savePlan(projectPlan);
        return HttpResult.ok();
    }

    @ApiOperation("删除")
    @DeleteMapping("delete")
    public HttpResult delete(Long id) {
        planService.delete(id);
        return HttpResult.ok();
    }
}
